var DOM = (document.getElementById) ? 1 : 0;
	var NS4 = (document.layers) ? 1 : 0;
	var IE4 = 0;
	if (document.all) {
		IE4 = 1;
		DOM = 0;
	}
	var win = window;
	var n = 0;
	
	function isIE() {
		return window.attachEvent;
	}
	
	function findIt() {
		if (document.getElementById("searchstr").value != "")
			findInPage(document.getElementById("searchstr").value);
	}
	function findInPage(str) {
		var txt, i, found = false;
		if (str == "")
			return false;
		if (DOM) {
			win.find(str, false, true);
			return true;
		}
		if (NS4) {
			if (!win.find(str))
				while (win.find(str, false, true)) {
					n++;
				}
			else
				n++;
			if (n == 0)
				alert("未找到指定内容.");
		}
		if (IE4) {
			txt = win.document.body.createTextRange();
			for (i = 0; i <= n && (found = txt.findText(str)) != false; i++) {
				txt.moveStart("character", 1);
				txt.moveEnd("textedit");
			}
			if (found) {
				txt.moveStart("character", -1);
				txt.findText(str);
				txt.select();
				txt.scrollIntoView();
				n++;
			} else {
				if (n > 0) {
					n = 0;
					findInPage(str);
				} else
					alert("未找到指定内容.");
			}
		}
		return false;
	}
	function cs(type) {
		document.body.setAttribute("contentEditable", true);
		document.execCommand(type, false, null);
		document.body.setAttribute("contentEditable", false);
	}
	function insert() {
		document.body.setAttribute("contentEditable", true);
		if (isIE()) {
			var pos = document.selection.createRange();
			if (pos.htmlText.length > 0) {
				pos.pasteHTML(pos.htmlText
						+ "<img src='http://3.su.bdimg.com/icon/114.png'>");
			}
		} else {
			var range = window.getSelection().getRangeAt(0);
			var img = document.createElement("img");
			img.setAttribute("src", "http://3.su.bdimg.com/icon/114.png");
			insertNode(range, img);
		}
		document.body.setAttribute("contentEditable", false);
	}
	function getInnerHTML(nodes) {
		if (navigator.userAgent.indexOf("Firefox") > 0) {
			return GetFireFoxInnerHTML(nodes);
		} else {
			return GetChormeInnerHTML(nodes);
		}
	}
	function GetFireFoxInnerHTML(nodes) {
		var result = '';
		var node;
		for ( var i = 0; i < nodes.length; i++) {
			node = nodes[i];
			if (node.nodeValue) {
				result += node.nodeValue;
			} else if (node.tagName) {
				result += "<" + node.tagName;
				if (node.innerHTML) {
					if (node.attributes && node.attributes.length > 1) {
						for ( var j = 0; j < node.attributes.length - 1; j++) // 忽略最后一个。
						{
							result += ' ' + node.attributes[j].name + "='"
									+ node.attributes[j].value + "'";
						}
					}
					result += ">" + node.innerHTML + "</" + node.tagName + ">";
				} else {
					result += " />";
				}

			}
		}
		return result;
	}
	function GetChormeInnerHTML(nodes) {
		var result = '';
		var node = null;
		for ( var i = 0; i < nodes.length; i++) {
			node = nodes[i];
			if (node.outerHTML) {
				result += node.outerHTML;
			} else if (node.nodeValue) {
				result += node.nodeValue;
			}
		}
		return result.replace("<div><br></div>","<br>");
	}

	function insertNode(range, node) {
	    var sc = range.endContainer,
	        so = range.endOffset,
	        p = sc.parentNode,
	        ns = sc.nextSibling,
	        nn, cn;
	    // 如果节点是 TEXT_NODE 或者 CDATA_SECTION_NODE
	    if ((sc.nodeType === 3 || sc.nodeType === 4 || sc.nodeType === 8 ) && sc.nodeValue) {
	        if (so === 0) {
	            // At the start of text
	            p.insertBefore(node, sc);
	        } else if (so >= sc.nodeValue.length) {
	            // At the end of text
	            if (ns) {
	                p.insertBefore(node, ns);
	            } else {
	                p.appendChild(node);
	            }
	        } else {
	            // Middle, need to split
	            nn = sc.splitText(so);
	            p.insertBefore(node, nn);
	        }
	    } else {
	        if (sc.childNodes.length > 0) {
	            cn = sc.childNodes[so];
	        }
	        if (cn) {
	            sc.insertBefore(node, cn);
	        } else {
	            sc.appendChild(node);
	        }
	    }
	}